// TOWN SCRIPT
//    Town 6: Under Putideum

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

int i,j,k,choice;
string dlgstr;

body;

beginstate INIT_STATE;
	set_crime_tolerance(1);
	
	i = 20;
	while (i <= 35) {
		j = 34;
		while (j <= 45) {
			change_blocked(i,j,1);
			j = j + 1;
			}
		i = i + 1;
		}
	change_blocked(20,36,0);
	change_blocked(21,37,0);
	change_blocked(22,37,0);
	change_blocked(23,38,0);
	change_blocked(24,37,0);
	change_blocked(25,36,0);
	change_blocked(26,36,0);
	change_blocked(26,35,0);
	change_blocked(27,35,0);
	change_blocked(28,34,0);
	change_blocked(29,35,0);
	change_blocked(30,36,0);
	change_blocked(31,36,0);
	change_blocked(32,37,0);
	change_blocked(33,38,0);
	change_blocked(34,37,0);
	change_blocked(34,38,0);
	
	if (get_flag(6,0) == 0) {
		set_flag(6,0,1);
		force_instant_terrain_redraw();
		message_dialog("As you descend the ladder, the air grows hotter, searing your lungs. Distant screams of agony and hatred reach your ears.","");
		}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
if ((get_crime_level() > 0) && (get_flag(250,4) == 0)) {
		set_flag(250,4,1);
		message_dialog("You feel a chill come over you. The gods have seen your crimes, and they will certainly punish you. The only questions are when and how.","");
		}
break;

beginstate 10;
	reset_dialog();
	add_dialog_str(0,"You have come to a ladder. Do you wish to climb it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb up.");
	if (run_dialog(1) == 2)
		move_to_new_town(0,7,15);
break;

beginstate 11;
if (get_flag(6,4) < 5) {
	block_entry(1);
	message_dialog("You have come to a ladder leading out of here, but you can't climb it yet, because there are still more bodies left to dispose of. You cannot move on until you observe proper ritual.","");
	end();
	}
	
	reset_dialog();
	add_dialog_str(0,"You have come to a ladder. Do you wish to climb it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb up.");
	if (run_dialog(1) == 2)
		move_to_new_town(0,6,21);
break;

beginstate 12;
if (get_flag(6,1) == 0) {
	reset_dialog();
	add_dialog_str(0,"In this box, you find a steel key. What do you wish to do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Take it.");
	if (run_dialog(1) == 2) {
		change_spec_item(1,1);
		set_flag(6,1,1);
		}
	}
break;

beginstate 13;
	reset_dialog();
	add_dialog_str(0,"You find a book that describes the rituals that have been performed on the dead bodies here. While alive, they were chained, burned slowly, limb by limb in the lava, and then whipped to death, when their tortures were not worse.",0);
	add_dialog_str(1,"Lord Putidus oversaw all of this; the notes written here are by him, describing in detail what to do to the victims, how to sacrifice them on the dark altars, what obscene rites to perform on their carcasses.",0);
	add_dialog_str(2,"You realize, as you read, that he was sacrificing these humans to himself! This is a doubly barbaric custom! Proper citizens of the empire do not practice human sacrifice, and only the Emperor himself can ever become a god and worthy of sacrifice.",0);
	add_dialog_str(3,"These are capital crimes. Your responsibility as representatives of imperial government here in the provinces is to bring him to justice.",0);
	add_dialog_str(4,"As you reach the end of the notes, you notice that evidently Lord Putidus likes to be called _Magnus Rex Putidus,_ since that is how he signs all of the notes.",0);
	run_dialog(1);
break;

beginstate 14;
if (get_flag(6,2) == 0) {
	reset_dialog();
	add_dialog_str(0,"The moment you step outside the room, you are surrounded by lava and buffeted with waves of heat. Has Putidus built his castle on an active volcano?",0);
	add_dialog_str(1,"The lava burns, but no light radiates from it. Instead, darkness visible emanates, flooding the air with a blackness to shadow all things. You also smell the infernal reek of sulfur.",0);
	add_dialog_str(2,"Before you, you see a dead body of a citizen of the empire, unburied. This is an outrage! The unburied must wait at the river Styx for a hundred years before they can cross into the land of the dead.",0);
	add_dialog_str(3,"Everything that you know, all of the values you have been taught, tell you that this man must be given a proper funeral ceremony and his body burned, not just in the lava, but in genuine fire. Pietas demands it.",0);
	add_dialog_str(4,"If Putidus has made it a habit to cast aside dead citizens like this, you will have to observe proper ritual before you can in good conscience move on.",0);
	set_flag(6,2,run_dialog(1));
	}
break;

beginstate 15;
if (get_flag(6,3) == 0) {
	message_dialog("Here is an altar with fires. You can bring the bodies here, approach the altar with them, and perform the proper burning ceremonies. You can use the pots in the back of the room to store the ashes once the bodies are burned.","The tools are somewhat crude -- Putidus probably intends this room for something else -- but the ritual is more important than the materials anyway.");
	set_flag(6,3,1);
	}
break;

beginstate 16;
if (has_item(451) == 0)
	end();
	
	reset_dialog();
	add_dialog_str(0,"You approach the altar. Do you perform the proper ceremony of cremation?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Perform the ritual.");
	if (run_dialog(1) == 2) {
		inc_flag(6,4,take_all_of_item(451));
		if (get_flag(6,4) == 5)
			message_dialog("You have burned all of the bodies here. You have fulfilled your duty. You may move on.","");
		}
break;

beginstate 17;
if (get_flag(6,5) == 0) {
	message_dialog("In this room, the floor is covered with seemingly random letters. They appear to be quite unstable, too: if you step on the wrong letter, the floor will give way, which would probably kill whoever stepped on it.","There must be some sort of pattern, a password, something that Putidus would like to be reminded of every time he has to get to whatever is beyond this.");
	set_flag(6,5,1);
	}
break;

beginstate 18;
if (get_flag(6,6) == 0) {
	message_dialog("You enter a storage room. You can tell by the boxes strewn about. However, based on the paintings on the wall, this is not just for junk; valuable things are down here, too.","Two of the statues seem to stare at you as you walk in.");
	set_flag(6,6,1);
	}
break;

beginstate 19;
if (get_flag(6,7) == 0) {
	message_dialog("Two of the statues come alive and attack you!","");
	set_terrain(44,41,0);
	set_terrain(44,44,0);
	activate_hidden_group(1);
	set_flag(6,7,1);
	}
break;